package edu.xaut.bookingsys.utils;


import cn.dev33.satoken.util.SaFoxUtil;
import cn.hutool.core.lang.Pair;
import cn.hutool.core.util.ObjectUtil;
import cn.hutool.core.util.ReUtil;
import edu.xaut.bookingsys.entity.InfoTeacher;
import edu.xaut.bookingsys.service.InfoTeacherService;
import org.springframework.stereotype.Component;

import java.time.LocalDate;

@Component
public class SomeUtils {


    // TODO 未实现
    public static int CalcWeekNums(LocalDate startDate, LocalDate nowDate) {

        return 0;
    }

    public static Pair<Boolean, String> validTeacherPasswordById(InfoTeacherService service, String id, String pwd) {
        // 用户查询
        InfoTeacher infoTeacher = service.getById(id);
        if (ObjectUtil.isNull(infoTeacher))
            return Pair.of(false, "无此帐户");
        // 密码校验
        try {
            if (!SecretUtils.checkRSAWithDESSql(id, pwd, infoTeacher.getPassword()))// 加密
            {
                return Pair.of(false, "密码不正确");
            }
        } catch (Exception e) {
            e.printStackTrace();
            return Pair.of(false, "密码解析错误");
        }
        // todo:此时用户信息 infoTeacher 应该保存在redis,避免对数据库的访问
        return Pair.of(true, "Ok");
    }
}
